<template>
  <el-dialog title="选择检验方式" v-model="show" center width="450px" top="70px" :append-to-body="true" :close-on-press-escape="true" :close-on-click-modal="false">
    <div class="v_dialog_body" v-loading="loading">
      <el-form :model="form" ref="form">
        <el-form-item label="检验方式" prop="testMode" :rules="[{ required: true, message: '请选择检验方式'}]" >
          <el-select size="mini" v-model="form.testMode" placeholder="请选择检验方式" clearable style="width: 100%">
            <el-option v-for="item in testModeList" :key="item.key" :label="item.name" :value="item.key"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="footer">
      <el-button  type="primary" icon="el-icon-check" size="small" v-on:click="doSave">确定</el-button>
      <el-button v-on:click="show = false" icon="el-icon-back" size="small">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>

export default {
  data() {
    return {
      loading: false,
      show: false,
      billNo: null,
      callback: null,
      form: {},
      testModeList: []
    }
  },
  async mounted() {
    await this.getTestMode()
  },
  methods: {
    async getTestMode() {
      this.loading = true;
      try {
        let res = await this.$api.getChildDictionaryListByKeys({
          keys: ['testMode']
        });
        if (!res.res) return;
        this.testModeList = res.testMode;
      } finally {
        this.loading = false;
      }
    },
    open (billNo,callback) {
      this.billNo = billNo
      this.callback = callback
      this.form = { testMode: '' }
      this.show = true
    },
    doSave() {
      return this.$refs.form.validate(async valid => {
        if (!valid) return;
        try {
          this.loading = true;
          await this.callback(this.billNo, this.form.testMode)
          this.show = false;
        } finally {
          this.loading = false;
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  padding: 0 10px 20px 10px;
}
</style>
